package com.ph.irp.base.verifyproject.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.ph.exception.PHException;
import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialBalancedeadlineDAO;
import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialAreaDAO;
import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialIndustryDao;
import com.ph.irp.base.verifyproject.dao.PBaseVerifyprogectSupplierDao;
import com.ph.irp.base.verifyproject.dao.PBaseVerifyprojectCandiateDao;
import com.ph.irp.base.verifyproject.dao.PBaseVerifyprojectDepartmentDao;
import com.ph.irp.base.verifyproject.service.PBaseVerifyprojectSupplierService;
import com.ph.irp.dto.SupplierDTO;
import com.ph.irp.model.PBaseAssistantmaterialArea;
import com.ph.irp.model.PBaseAssistantmaterialBalancedeadline;
import com.ph.irp.model.PBaseAssistantmaterialIndustry;
import com.ph.irp.model.PBaseVerifyprojectCandiate;
import com.ph.irp.model.PBaseVerifyprojectDepartment;
import com.ph.irp.model.PBaseVerifyprojectSupplier;

public class PBaseVerifyprogectSupplierServiceImpl implements
		PBaseVerifyprojectSupplierService {

	private PBaseVerifyprogectSupplierDao supplierDaoProxy;
	private PBaseVerifyprojectDepartmentDao departmentDaoProxy;
	private PBaseVerifyprojectCandiateDao candiateDaoProxy;
	private PBaseAssistantmaterialIndustryDao assistantmaterialIndustryDaoProxy;
	private PBaseAssistantmaterialAreaDAO areaDAOProxy;
	private PBaseAssistantmaterialBalancedeadlineDAO deadlineDAOProxy;

	public PBaseVerifyprogectSupplierDao getSupplierDaoProxy() {
		return supplierDaoProxy;
	}

	public void setSupplierDaoProxy(
			PBaseVerifyprogectSupplierDao supplierDaoProxy) {
		this.supplierDaoProxy = supplierDaoProxy;
	}

	public PBaseVerifyprojectDepartmentDao getDepartmentDaoProxy() {
		return departmentDaoProxy;
	}

	public void setDepartmentDaoProxy(
			PBaseVerifyprojectDepartmentDao departmentDaoProxy) {
		this.departmentDaoProxy = departmentDaoProxy;
	}

	public PBaseVerifyprojectCandiateDao getCandiateDaoProxy() {
		return candiateDaoProxy;
	}

	public void setCandiateDaoProxy(
			PBaseVerifyprojectCandiateDao candiateDaoProxy) {
		this.candiateDaoProxy = candiateDaoProxy;
	}

	public PBaseAssistantmaterialIndustryDao getAssistantmaterialIndustryDaoProxy() {
		return assistantmaterialIndustryDaoProxy;
	}

	public void setAssistantmaterialIndustryDaoProxy(
			PBaseAssistantmaterialIndustryDao assistantmaterialIndustryDaoProxy) {
		this.assistantmaterialIndustryDaoProxy = assistantmaterialIndustryDaoProxy;
	}

	public PBaseAssistantmaterialAreaDAO getAreaDAOProxy() {
		return areaDAOProxy;
	}

	public void setAreaDAOProxy(PBaseAssistantmaterialAreaDAO areaDAOProxy) {
		this.areaDAOProxy = areaDAOProxy;
	}

	public PBaseAssistantmaterialBalancedeadlineDAO getDeadlineDAOProxy() {
		return deadlineDAOProxy;
	}

	public void setDeadlineDAOProxy(
			PBaseAssistantmaterialBalancedeadlineDAO deadlineDAOProxy) {
		this.deadlineDAOProxy = deadlineDAOProxy;
	}

	@Override
	public void addSupplier(PBaseVerifyprojectSupplier model) throws Throwable {
		supplierDaoProxy.addSupplier(model);
	}

	public void deleteSupplier(Object[] supplierId) throws Throwable {
		for (int i = 0; i < supplierId.length; i++) {
			supplierDaoProxy.deleteSupplier(Integer
					.valueOf((String) supplierId[i]));
		}
	}

	@Override
	public List<SupplierDTO> getAllSupplier() throws Throwable {
		List<SupplierDTO> list = new ArrayList<SupplierDTO>();
		List<PBaseVerifyprojectSupplier> sList;

		sList = supplierDaoProxy.getAllSupplier();

		for (PBaseVerifyprojectSupplier supplier : sList) {
			SupplierDTO supplierDTO = new SupplierDTO();
			if (supplier.getPBaseAssistantmaterialAreaId() != 0) {
				PBaseAssistantmaterialArea areaModel = new PBaseAssistantmaterialArea();
				areaModel = areaDAOProxy.getAssistantmaterialAreaById(supplier
						.getPBaseAssistantmaterialAreaId());
				supplierDTO.setArea(areaModel);
			}
			if (supplier.getPBaseAssistantmaterialBalancedeadlineId() != 0) {
				PBaseAssistantmaterialBalancedeadline line = new PBaseAssistantmaterialBalancedeadline();
				line = deadlineDAOProxy.getBalancedeadlineById(supplier
						.getPBaseAssistantmaterialBalancedeadlineId());
				supplierDTO.setBala(line);

			}
			if (supplier.getPBaseAssistantmaterialIndustryId() != 0) {
				PBaseAssistantmaterialIndustry in = new PBaseAssistantmaterialIndustry();
				in = assistantmaterialIndustryDaoProxy
						.getPBaseAssistantmaterialIndustryById(supplier
								.getPBaseAssistantmaterialIndustryId());
				supplierDTO.setIndustry(in);
			}
			if (supplier.getPBaseVerifyprojectCandiateId() != 0) {
				PBaseVerifyprojectCandiate candiate = new PBaseVerifyprojectCandiate();

				candiate = candiateDaoProxy.getCandiateById(supplier
						.getPBaseVerifyprojectCandiateId());
				supplierDTO.setCadiate(candiate);
			}

			if (supplier.getPBaseVerifyprojectDepartmentId() != 0) {
				PBaseVerifyprojectDepartment dept = new PBaseVerifyprojectDepartment();
				dept = departmentDaoProxy.getDepartmentById(supplier
						.getPBaseVerifyprojectDepartmentId());
				supplierDTO.setDept(dept);
			}
			supplierDTO.setSupplier(supplier);
			list.add(supplierDTO);
		}
		return list;
	}

	public List<SupplierDTO> getSupplierByCondition(
			PBaseVerifyprojectSupplier model) throws Throwable {
		List<SupplierDTO> list = new ArrayList<SupplierDTO>();
		List<PBaseVerifyprojectSupplier> sList;

		sList = supplierDaoProxy.getSupplierByCondition(model);

		for (PBaseVerifyprojectSupplier supplier : sList) {
			SupplierDTO supplierDTO = new SupplierDTO();
			if (supplier.getPBaseAssistantmaterialAreaId() != 0) {
				PBaseAssistantmaterialArea areaModel = new PBaseAssistantmaterialArea();
				areaModel = areaDAOProxy.getAssistantmaterialAreaById(supplier
						.getPBaseAssistantmaterialAreaId());
				supplierDTO.setArea(areaModel);
			}
			if (supplier.getPBaseAssistantmaterialBalancedeadlineId() != 0) {
				PBaseAssistantmaterialBalancedeadline line = new PBaseAssistantmaterialBalancedeadline();
				line = deadlineDAOProxy.getBalancedeadlineById(supplier
						.getPBaseAssistantmaterialBalancedeadlineId());
				supplierDTO.setBala(line);

			}
			if (supplier.getPBaseAssistantmaterialIndustryId() != 0) {
				PBaseAssistantmaterialIndustry in = new PBaseAssistantmaterialIndustry();
				in = assistantmaterialIndustryDaoProxy
						.getPBaseAssistantmaterialIndustryById(supplier
								.getPBaseAssistantmaterialIndustryId());
				supplierDTO.setIndustry(in);
			}
			if (supplier.getPBaseVerifyprojectCandiateId() != 0) {
				PBaseVerifyprojectCandiate candiate = new PBaseVerifyprojectCandiate();

				candiate = candiateDaoProxy.getCandiateById(supplier
						.getPBaseVerifyprojectCandiateId());
				supplierDTO.setCadiate(candiate);
			}

			if (supplier.getPBaseVerifyprojectDepartmentId() != 0) {
				PBaseVerifyprojectDepartment dept = new PBaseVerifyprojectDepartment();
				dept = departmentDaoProxy.getDepartmentById(supplier
						.getPBaseVerifyprojectDepartmentId());
				supplierDTO.setDept(dept);
			}
			supplierDTO.setSupplier(supplier);
			list.add(supplierDTO);
		}
		return list;

	}

	@Override
	public PBaseVerifyprojectSupplier getSupplierById(int supplierId)
			throws Throwable {
		PBaseVerifyprojectSupplier supplier = supplierDaoProxy
				.getSupplierById(supplierId);

		return supplier;
	}

	@Override
	public void updateSupplier(PBaseVerifyprojectSupplier model)
			throws Throwable {

		supplierDaoProxy.updateSupplier(model);
	}

}
